package com.xlh.dao.user.helper;

import cn.hutool.core.collection.CollectionUtil;
import com.xlh.dao.user.UserClassMapper;
import com.xlh.pojo.user.UserClass;
import com.xlh.pojo.user.UserClassExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author cfz
 */
@Repository
public class UserClassMapperHelper {

    @Autowired
    private UserClassMapper userClassMapper;

    public List<UserClass> findByCondition(Long classId){

        UserClassExample example = new UserClassExample();
        example.createCriteria().andClassIdEqualTo(classId).andDeletedEqualTo(false);
        List<UserClass> userClasses = userClassMapper.selectByExample(example);
        return userClasses;
    }

    /**
     * 获取studentID 根据userId和classId
     * @param classId
     * @param userId
     * @return
     */
    public UserClass findByCondition(Long classId, Long userId){

        UserClassExample example = new UserClassExample();
        example.createCriteria().andClassIdEqualTo(classId).andUserIdEqualTo(userId)
                .andDeletedEqualTo(false);
        List<UserClass> userClasses = userClassMapper.selectByExample(example);
        if(CollectionUtil.isNotEmpty(userClasses)){

            return userClasses.get(0);
        }
        return null;
    }



    /**
     * 查询用户信息根据studentId
     * @param studentIds
     * @return
     */
    public List<UserClass> findByStudentIds(List<Long> studentIds) {

        UserClassExample example = new UserClassExample();
        example.createCriteria().andIdIn(studentIds).andDeletedEqualTo(false);
        List<UserClass> userClasses = userClassMapper.selectByExample(example);
        return userClasses;
    }


    /**
     * 获取根据ID
     * @param id
     * @return
     */
    public UserClass getById( Long id ){

        return userClassMapper.selectByPrimaryKey(id);
    }


}
